﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LambdaToSql.TableStruct
{
    internal abstract class BaseTable
    {
        /// <summary>
        /// 缓存帮助类
        /// </summary>
        public FrameWork.CacheHelper Cache = FrameWork.CacheHelper.Instance;

        /// <summary>
        /// 数据库上下文对象
        /// </summary>
        public LambdaToSql.EntityModel.DbContext Context { get; set; }

        /// <summary>
        /// 表结构
        /// </summary>
        public Dictionary<string, LambdaToSql.EntityModel.Table> DicTable
        {
            get
            {
                Dictionary<string, LambdaToSql.EntityModel.Table> table;
                if (!string.IsNullOrEmpty(this.Context.ConnectionStringName))
                {
                    if (Cache[this.Context.ConnectionStringName] != null)
                    {
                        table = Cache[this.Context.ConnectionStringName] as Dictionary<string, LambdaToSql.EntityModel.Table>;
                    }
                    else
                    {
                        table = GetDataTable();
                        Cache[this.Context.ConnectionStringName] = table;
                    }
                }
                else
                {
                    table = GetDataTable();
                }
                return table;
            }
        }

        /// <summary>
        /// 获取数据库表字段实体
        /// </summary> 
        /// <returns></returns>
        public virtual Dictionary<string, LambdaToSql.EntityModel.Table> GetDataTable()
        {
            return null;
        }
    }
}
